#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

struct A
{
    int x;
    int y;
};
void *Execute(void* args)
{
    // return (void*)"666";
    int* result = new int;
    *result =((A*)args)->x+((A*)args)->y;
    std::cout<<"result:"<<*result<<std::endl;
    pthread_exit((void*)result);
}
void *Execute2(void* args)
{
    // return (void*)"666";
    int* result = new int;
    ((A*)args)->x-=99;
    *result =((A*)args)->x+((A*)args)->y;
    std::cout<<"result:"<<*result<<std::endl;
    pthread_exit((void*)result);
}



int main()
{
    std::vector<pthread_t> tids;
    for(int i =0;i<10;i++)
    {
        pthread_t tid;
        int c =0;
        A b;
        A * a=&b;
        // A* a =new A;
        a->x++;
        a->y++;
        if(i!=5)
        pthread_create(&tid,nullptr,Execute,(void*)a);
        else
        pthread_create(&tid,nullptr,Execute2,(void*)a);

        std::cout<<&c<<std::endl;

        void * ret;
        pthread_join(tid,&ret);
        tids.push_back(tid);
        std::cout<<*(int*)ret<<std::endl;
        sleep(1);
    }
    
    return 0;
}